package edu.mit.media.fv.aqwidgets
{
	import edu.mit.media.fv.blocks.*;
	import edu.mit.media.fv.components.*;
	import edu.mit.media.fv.events.*;
	import edu.mit.media.fv.fluidspace.*;
	import edu.mit.media.fv.icons.*;
	
	import flash.display.*;
	import flash.events.*;
	import flash.filters.*;
	import flash.text.*;
	import flash.utils.Timer;
	import edu.mit.media.fv.blocks.*;
	import edu.mit.media.fv.components.*;
	import edu.mit.media.fv.events.*;
	import edu.mit.media.fv.fluidspace.*;
	
	import flash.display.DisplayObject;
	import flash.display.MovieClip;
	import flash.display.Sprite;
	import flash.events.TimerEvent;
	import flash.utils.Timer;
	
	public class AQIconTray extends MovieClip
	{
		var _nameLabel:TextField;
		
		private var username:String = "";
		private var timer:Timer;
		
		private static var glow:GlowFilter = new GlowFilter(0x000000,0.6,20,20);
		public function AQIconTray()
		{
			super();
			this.filters = [glow];
			
			this.timer = new Timer(3000, 1);
			this.timer.addEventListener(TimerEvent.TIMER, onTimer);
			this.timer.addEventListener(TimerEvent.TIMER_COMPLETE, onTimerComplete);
			
			FluidEventHandler.addEventListener(AudioEvent.MUTE, processMute);
			FluidEventHandler.addEventListener(AudioEvent.UNMUTE, processUnMute);
			FluidEventHandler.addEventListener(WidgetEvent.DISPLAY_WIDGET, displayWidget);
		}
		public function displayWidget(event:WidgetEvent):void{
			this.timer.reset();
			this._nameLabel.text = event.text;
			
		}
		private function onTimer(event:Timer):void{
			trace("Setting name");
		}
		private function onTimerComplete(event:TimerEvent):void{
			this._nameLabel.text = username;
			this.timer.reset();
		}
		private function workspaceListener(event:MouseEvent):void{
			FluidEventHandler.dispatchEvent(new WidgetEvent(
				WidgetEvent.DISPLAY_WORKSPACE));
		}
		private function navigatorListener(event:MouseEvent):void{
			FluidEventHandler.dispatchEvent(new WidgetEvent(
				WidgetEvent.DISPLAY_NAVIGATOR));
		}
		private function groupListener(event:MouseEvent):void{
			FluidEventHandler.dispatchEvent(new WidgetEvent(
				WidgetEvent.DISPLAY_GROUP_VIEW));
		}
		private function messageListener(event:MouseEvent):void{
			FluidEventHandler.dispatchEvent(new WidgetEvent(
				WidgetEvent.DISPLAY_MESSAGE_BUILDER));
		}
		private function timelineListener(event:MouseEvent):void{
			FluidEventHandler.dispatchEvent(new WidgetEvent(
				WidgetEvent.DISPLAY_TIMELINE));
		}

		
		public function processMute(event:AudioEvent):void{
			var data:Object = new Object();
			data.command = FluidConstants.REQUEST_MUTE;
			var e:FVNetworkEvent = new FVNetworkEvent(data);
			FluidEventHandler.dispatchEvent(e);
		}
		public function processUnMute(event:AudioEvent):void{
			var data:Object = new Object();
			data.command = FluidConstants.REQUEST_UNMUTE;
			var e:FVNetworkEvent = new FVNetworkEvent(data);
			FluidEventHandler.dispatchEvent(e);
		}
	}
}